local fuhai = fk.CreateSkill {

  name = "joy__fuhai",

  tags = { Skill.Compulsory, },

}



fuhai:addEffect(fk.TargetSpecified, {
  name = "joy__fuhai",
  events = {fk.TargetSpecified, fk.Death},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(fuhai.name) then return false end
    if event == fk.TargetSpecified then
      return target == player and player.room:getPlayerById(data.to):getMark("@joy__yingba_pingding") > 0
    else
      return player.room:getPlayerById(data.who):getMark("@joy__yingba_pingding") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      data.disresponsiveList = data.disresponsiveList or {}
      table.insert(data.disresponsiveList, data.to)
      if player:getMark("joy__fuhai_draw-turn") < 2 then
        room:addPlayerMark(player, "joy__fuhai_draw-turn")
        player:drawCards(1, fuhai.name)
      end
    else
      local pingdingNum = target:getMark("@joy__yingba_pingding")
      room:changeMaxHp(player, pingdingNum)
      player:drawCards(pingdingNum, fuhai.name)
    end
  end,
})
fuhai:addEffect(fk.Death, {
  name = "joy__fuhai",
  events = {fk.TargetSpecified, fk.Death},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(fuhai.name) then return false end
    if event == fk.TargetSpecified then
      return target == player and player.room:getPlayerById(data.to):getMark("@joy__yingba_pingding") > 0
    else
      return player.room:getPlayerById(data.who):getMark("@joy__yingba_pingding") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      data.disresponsiveList = data.disresponsiveList or {}
      table.insert(data.disresponsiveList, data.to)
      if player:getMark("joy__fuhai_draw-turn") < 2 then
        room:addPlayerMark(player, "joy__fuhai_draw-turn")
        player:drawCards(1, fuhai.name)
      end
    else
      local pingdingNum = target:getMark("@joy__yingba_pingding")
      room:changeMaxHp(player, pingdingNum)
      player:drawCards(pingdingNum, fuhai.name)
    end
  end,
})

return fuhai